1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class Paddle : MonoBehaviour {
6
7     
public bool autoPlay = false;
8
9     
private Ball ball;
10
11     
void Start()
12     {
13         ball = GameObject.FindObjectOfType<Ball>();
14     }
15
16     
// Update is called once per frame
17     
void Update ()
18     {
19         
if (!autoPlay)
20         {
21             MoveWithMouse();
22         }
23         
else
24         {
25             Autoplay();
26         }
27     }
28
29     
void Autoplay()
30     {
31         Vector3 mousePosInBlocks = ball.transform.position;
32         Vector3 paddlePos =
new Vector3(1.95f, this.transform.position.y, 0f);
33         paddlePos.x = Mathf.Clamp(mousePosInBlocks.x,
2.19f, 13.8f);
34         transform.position = paddlePos;
35     }
36
37     
void MoveWithMouse()
38     {
39         
float mousePosInBlocks = (Input.mousePosition.x / Screen.width * 16);
40         Vector3 paddlePos =
new Vector3(1.95f, this.transform.position.y, 0f);
41         paddlePos.x = Mathf.Clamp(mousePosInBlocks,
2.19f, 13.8f);
42         transform.position = paddlePos;
43     }
44 }


Gõ tìm kiếm nhanh...